/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.util.Date;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import pojo.Static;
import ulti.HibernateUtil;

/**
 *
 * @author phong
 */
public class StaticDAO {
    //<editor-fold defaultstate="collapsed" desc="Lấy thong ke các Lab duoc dang ki">

    public static List<Static> getStatictLab() {
        List<Static> Statics = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            String hql = "select new pojo.Static(l,count(l.id)) from Lab l, in(l.signLabs) s"
                    + " GROUP BY l.id";
            Query query = session.createQuery(hql);
            Statics = query.list();
        } catch (HibernateException ex) {
            System.err.println(ex);
        }
        return Statics;
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Lấy thong ke các Lab duoc dang ki thong qua timeTable">
    public static List<Static> getStatictLab(String timeTableID) {
        List<Static> Statics = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            String hql = "select new pojo.Static(l,count(l.id)) from Lab l, in(l.signLabs) s"
                    + " where s.timeTable.id = :timeTableID"
                    + " GROUP BY l.id";
            Query query = session.createQuery(hql);
            query.setString("timeTableID", timeTableID);
            Statics = query.list();
        } catch (HibernateException ex) {
            System.err.println(ex);
        }
        return Statics;
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Lấy thong ke các Lab duoc dang ki giua 2 ngay">
    public static List<Static> getStatictLab(Date startDate, Date endDate) {
        List<Static> Statics = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            String hql = "select new pojo.Static(l,count(l.id)) from Lab l, in(l.signLabs) s "
                    + " where s.useDate between :startDate and :endDate"
                    + " GROUP BY l.id";
            Query query = session.createQuery(hql);
            query.setDate("startDate", startDate);
            query.setDate("endDate", endDate);
            Statics = query.list();
        } catch (HibernateException ex) {
            System.err.println(ex);
        }
        return Statics;
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Lấy thong ke các Lab duoc dang ki thong qua timeTable giua 2 ngay">
    public static List<Static> getStatictLab(Date startDate, Date endDate, String timeTableID) {
        List<Static> Statics = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            String hql = "select new pojo.Static(l,count(l.id)) from Lab l, in(l.signLabs) s"
                    + " where s.timeTable.id = :timeTableID"
                    + " and (s.useDate between :startDate and :endDate)"
                    + " GROUP BY l.id";
            Query query = session.createQuery(hql);
            query.setString("timeTableID", timeTableID);
            query.setDate("startDate", startDate);
            query.setDate("endDate", endDate);
            Statics = query.list();
        } catch (HibernateException ex) {
            System.err.println(ex);
        }
        return Statics;
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Lấy thong ke các Lab duoc su dung">
    public static List<Static> getStatictLabUsed() {
        List<Static> Statics = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            String hql = "select new pojo.Static(l,count(l.id)) from Lab l, in(l.signLabs) s"
                    + " where s.status ='Approve' or s.status ='Done'"
                    + " GROUP BY l.id";
            Query query = session.createQuery(hql);
            Statics = query.list();
        } catch (HibernateException ex) {
            System.err.println(ex);
        }
        return Statics;
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Lấy thong ke các Lab duoc su dung thong qua timeTable">
    public static List<Static> getStatictLabUsed(String timeTableID) {
        List<Static> Statics = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            String hql = "select new pojo.Static(l,count(l.id)) from Lab l, in(l.signLabs) s"
                    + " where (s.status ='Approve' or s.status ='Done')"
                    + " and s.timeTable.id = :timeTableID"
                    + " GROUP BY l.id";
            Query query = session.createQuery(hql);
            query.setString("timeTableID", timeTableID);
            Statics = query.list();
        } catch (HibernateException ex) {
            System.err.println(ex);
        }
        return Statics;
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Lấy thong ke các Lab duoc su dung giua 2 ngay">
    public static List<Static> getStatictLabUsed(Date startDate, Date endDate) {
        List<Static> Statics = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            String hql = "select new pojo.Static(l,count(l.id)) from Lab l, in(l.signLabs) s"
                    + " where (s.status ='Approve' or s.status ='Done')"
                    + " and (s.useDate between :startDate and :endDate)"
                    + " GROUP BY l.id";
            Query query = session.createQuery(hql);
            query.setDate("startDate", startDate);
            query.setDate("endDate", endDate);
            Statics = query.list();
        } catch (HibernateException ex) {
            System.err.println(ex);
        }
        return Statics;
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Lấy thong ke các Lab duoc su dung thong qua timeTable giua 2 ngay">
    public static List<Static> getStatictLabUsed(Date startDate, Date endDate, String timeTableID) {
        List<Static> Statics = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            String hql = "select new pojo.Static(l,count(l.id)) from Lab l, in(l.signLabs) s"
                    + " where (s.status ='Approve' or s.status ='Done')"
                    + " and s.timeTable.id = :timeTableID"
                    + " and (s.useDate between :startDate and :endDate)"
                    + " GROUP BY l.id";
            Query query = session.createQuery(hql);
            query.setString("timeTableID", timeTableID);
            query.setDate("startDate", startDate);
            query.setDate("endDate", endDate);
            Statics = query.list();
        } catch (HibernateException ex) {
            System.err.println(ex);
        }
        return Statics;
    }
    //</editor-fold>
}
